﻿using System;
using Zeus.Thunder.Core;

namespace SharpTrainer.Delegates
{
  public delegate bool ComparisonHandler2(int first, int second);

  class AnonymousDelegate : ITestCase
  {
    public void Run()
    {
      int i;
      int[] items = new int[5];
      ComparisonHandler2 comparisonMethod;

      for (i = 0; i < items.Length; i++)
      {
        Console.Write("Enter an integer: ");
        items[i] = int.Parse(Console.ReadLine());
      }

      comparisonMethod =
        delegate(int first, int second)
        {
          return first < second;
        };

      Sort(items, comparisonMethod);

      for (i = 0; i < items.Length; i++)
      {
        Console.WriteLine(items[i]);
      }

      Console.ReadLine();
    }

    static void Sort(int[] items, ComparisonHandler2 comparisonMethod)
    {
      int i;
      int j;
      int temp;

      for (i = items.Length - 1; i >= 0; i--)
      {
        for (j = 1; j <= i; j++)
        {
          if (comparisonMethod(items[j - 1], items[j]))
          {
            temp = items[j - 1];
            items[j - 1] = items[j];
            items[j] = temp;
          }
        }
      }
    }
  }
  
}
